package com.chenshu.jdbc;

import com.chenshu.jdbc.dao.StudentDao;
import com.chenshu.jdbc.model.Student;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2024-04-03
 * Time：10:56
 */
public class Test {
    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext("druid-jdbc.xml");
//        JdbcTemplate jdbcTemplate = (JdbcTemplate) context.getBean("jdbcTemplate");
//        String sql =
//                "Create table tb_student" +
//                        "(stu_id char(11) primary key, " +
//                        "name varchar(15) not null, " +
//                        "gender varchar(10)," +
//                        "age int)";
//
//        jdbcTemplate.execute(sql);

        StudentDao studentDao = context.getBean("studentDao", StudentDao.class);

        System.out.println("插入学生信息");
//        Student student = new Student("12021052019", "chenshu", "男", 21);
//        studentDao.addStuInfo(student);

        System.out.println("查询所有学生信息");
        List<Student> students = studentDao.findAll();
        for (Student student : students) {
            System.out.println(student);
        }

    }
}
